<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <!-- <el-form-item>
          <el-input v-model="filters.id" placeholder="ID"></el-input>
        </el-form-item> -->
        <!-- <el-form-item>
          <el-input v-model="filters.productId" placeholder="产品ID"></el-input>
        </el-form-item> -->
        <el-row>
          <el-form-item>
            <el-select size="small" clearable style="width:200px;" v-model="filters.branchCode" @change="selectVal" placeholder="请选择选择机构">
              <el-option v-for="(item,index) in filters.items" :key="index" :label="item.codeCname" :value="item.code"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item v-show="exportBtnVisible" style="float:right;">
            <el-button size="small" class="button_style" type="primary" icon="upload2" @click="exportExcels">导出</el-button>
          </el-form-item>
          <el-form-item v-show="configBtnVisible" style="float:right;">
            <el-button size="small" class="button_style" type="primary" @click="handleAdd" icon="edit">配置地区</el-button>
          </el-form-item>
          <el-form-item v-show="addBtnVisible" style="float:right;">
            <el-button size="small" class="button_style" type="primary" @click="Addarea" icon="plus">新增地区</el-button>
          </el-form-item>
        </el-row>
      </el-form>
    </el-col>

    <!--列表-->
    <el-table :data="branchs" stripe border :height="winHeight-188" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width:100%;">
      <!--       <el-table-column type="selection" width="55">
      </el-table-column> -->
      <el-table-column prop="branchName" label="机构名称" min-width="140px" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="branchEname" label="机构英文名" min-width="120px" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="branchCode" label="机构编码" min-width="120px">
      </el-table-column>
      <el-table-column prop="areaName" label="地区名称" min-width="120px">
      </el-table-column>
      <el-table-column prop="areaCode" label="地区编码" min-width="120px">
      </el-table-column>
      <el-table-column prop="agreementNo" label="业务关系代码" min-width="130px">
      </el-table-column>
      <el-table-column prop="saleName" label="销售人员" min-width="120px" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="saleCode" label="销售编码" min-width="120px" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="contactMobile" label="联系人手机" min-width="120px" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="contactEmail" label="联系人邮箱" min-width="120px" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="invoiceStatus" label="是否开具发票" min-width="140px" :formatter="formatStatus">
      </el-table-column>
      <el-table-column prop="insurancePolicyStatus" label="是否开具电子保单" min-width="150px" :formatter="formatPolicyStatus">
      </el-table-column>
      <!--  <el-table-column label="操作" fixed='right' width="120">
        <template scope="scope">
          <el-button size="small" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
          <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <!-- <el-button type="danger" @click="batchRemove"  :disabled="this.sels.length===0">批量删除</el-button> -->
      <!-- <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="10" :total="total" style="float:right;">
      </el-pagination> -->

      <el-pagination style="float:right" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page" :page-sizes="[10, 20, 40, 80]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </el-col>
    <!--添加-->
    <el-dialog :title="'配置地区('+organuzationName+')'" v-model="addFormVisible" :close-on-click-modal="false">
      <!-- <el-dialog     v-model="addFormVisible" :close-on-click-modal="false">
    <div class="dialog_title_style">
      {{'配置地区('+organuzationName+')'}}
    </div> -->
      <el-transfer style="margin-left:17%;" v-model="addNape" :titles="['可添加地区','已添加地区']" :data="addData" @change="handleChange"></el-transfer>
      <el-form :model="getAgreementNo" style="margin-top:20px;" label-width="160px" :rules="addFormRules" ref="getAgreementNo">
        <el-form-item label="是否可以开具发票" prop="invoiceStatus">
          <el-radio-group v-model="getAgreementNo.invoiceStatus">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否可以开具电子保单" prop="insurancePolicyStatus">
          <el-radio-group v-model="getAgreementNo.insurancePolicyStatus">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="机构联系人手机" prop="contactMobile">
          <el-input v-model="getAgreementNo.contactMobile" autofocus="autofocus" style="width:80%">
          </el-input>
        </el-form-item>
        <el-form-item label="机构联系人邮箱" prop="contactEmail">
          <el-input v-model="getAgreementNo.contactEmail" autofocus="autofocus" style="width:80%">
          </el-input>
        </el-form-item>
        <el-form-item label="业务关系代码" prop="agreementNo">
          <el-input v-model="getAgreementNo.agreementNo" autofocus="autofocus" style="width:80%" @change="blurSelect">
          </el-input>
        </el-form-item>
        <el-form-item label="销售人名称和编码" v-show="sellShow">
          <!-- <el-input v-model="getAgreementNo.saleCode"  auto-complete="off" ></el-input> -->
          <!-- <el-autocomplete
                          v-model="state4"
                          style="width:90%;"
                          :fetch-suggestions="querySearchAsync"
                          placeholder="请输入姓名"
                          @select="handleSelect"
                        >
                        </el-autocomplete> -->

          <el-select v-model="selectdatas" clearable style="width:80%" @change="handleSelect" @visible-change="visibleSelect" placeholder="请选择">
            <el-option v-for="(item,index) in restaurants" :key="index" :label="item.value" :value="item.code">
              <span style="float: left">{{ item.value }}</span>
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="addFormVisible = false">取消</el-button>
        <el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
      </div>
    </el-dialog>

    <!--新增地区-->
    <el-dialog title="新增地区" v-model="addareaVisible" :close-on-click-modal="false">
      <el-form label-width="100px" :model="addarea" :rules="addareaRules" ref="addarea">
        <el-row>
          <el-col :xs="24" :sm="20" :md="12" :lg="12">
            <el-form-item label="地区中文名:" prop="areaCname">
              <el-input v-model.trim="addarea.areaCname" auto-complete="off" placeholder="请输入地区中文名">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="20" :md="12" :lg="12">
            <el-form-item label="地区英文名:" prop="areaEname">
              <el-input v-model.trim="addarea.areaEname" auto-complete="off" placeholder="请输入地区英文名">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="20" :md="12" :lg="12">
            <el-form-item label="地区编码:" prop="areaCname">
              <el-input v-model.trim="addarea.areaCode" auto-complete="off" placeholder="请输入地区编码">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="20" :md="12" :lg="12">
            <el-form-item label="所属机构:" prop="areaEname">
              <el-select clearable style="width:100%;" v-model="addarea.branchCode" placeholder="请选择机构(可选)">
                <el-option v-for="(item,index) in items" :key="index" :label="item.codeCname" :value="item.code"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="addareaVisible = false">取消</el-button>
        <el-button type="primary" @click.native="addareaSubmit" :loading="addareaLoading">提交</el-button>
      </div>
    </el-dialog>
    <!--修改界面-->
    <el-dialog title="修改" v-model="editFormVisible" :close-on-click-modal="false">
      <el-form :model="editForm" :inline="true" label-width="120px" :rules="editFormRules" ref="editForm">
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="editFormVisible = false">取消</el-button>
        <el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
      </div>
    </el-dialog>
  </section>
</template>

<script>
import util from '../../common/js/util'
import commons from '../../common/js/common'
import { mapState, mapActions } from 'vuex'
//import NProgress from 'nprogress'
import { areaHotProductList, removeProduct, batchRemoveUser, addProduct, getHotProduct, removeHotProduct, areaList, getUserListPage, codeNodeList, addArea, removeArea, getAgreementNo, notConfiguredArea, getSaleName, addNewArea } from '../../api/api';

export default {
  data() {
    var phone = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('手机号码不能为空'));
      }
      else {
        if (!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(value))) {
          callback(new Error('请输入正确的手机号码'));
        }
        else {
          callback();
        }
      }
    };

    var Email = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('邮箱不能为空'));
      }
      else {
        if (!(/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/.test(value))) {
          callback(new Error('请输入正确的邮箱'));
        }
        else {
          callback();
        }
      }
    };

    return {
      selectdatas: '',
      selectValue: '',
      restaurants: [{
        value: '',
        code: ''
      }],
      state4: '',
      organuzationName: '',//机构名称
      timeout: null,
      filters: {
        branchCode: '',
        items: ''
        // area:''
      },
      items: [],
      sellShow: true,
      exportTotal: 0,
      loading: '',
      branchName: '',
      branchs: [],
      addData: [],//地区列表Data(左)
      addNape: [],//添加地区(右)
      StartLeftData: [],
      StartRightData: [],
      LeftsData: [],
      RightsData: [],
      addAarry: [],
      delAarry: [],
      lists: [],
      total: 0,
      page: 1,
      pageSize: 10,
      Forminline: true,
      IsSelect: true,
      // titles:['大','啊'],
      listLoading: false,
      sels: [],//列表选中列
      editFormVisible: false,//修改界面是否显示
      editLoading: false,
      editFormRules: {
        // name: [
        //   { required: true, message: '请输入姓名', trigger: 'blur' }
        // ]
      },
      //
      getAgreementNo: {
        agreementNo: '',
        saleCode: '',
        saleName: '',
        contactMobile: '',
        contactEmail: '',
        invoiceStatus: 1,
        insurancePolicyStatus: 1
      },
      //修改界面数据
      editForm: {
        id: '',
        codeCname: '',
        codeEname: '',
        branchCode: '',
        remark: ''
      },
      addFormVisible: false,//新增界面是否显示
      addareaVisible: false,//新增地区是否显示
      addFormRules: {
        agreementNo: [
          { required: true, message: '请输入业务关系代码', trigger: 'blur' }
        ],
        saleName: [
          { required: true, message: '请选择销售人名称', trigger: 'blur' }
        ],
        saleCode: [
          { required: true, message: '请选择销售人编码', trigger: 'blur' }
        ],
        contactMobile: [
          { required: true, validator: phone, trigger: 'blur' }
        ],
        contactEmail: [
          { required: true, validator: Email, trigger: 'blur' }
        ],
      },
      addareaRules: {
        areaCname: [
          { required: true, message: '请输入地区中文名', trigger: 'blur' }
        ],
        areaCode: [
          { required: true, message: '请输入地区编码', trigger: 'blur' }
        ]
      },
      addLoading: false,
      addareaLoading: false,
      //新增界面数据
      addForm: {
        id: '',
        codeCname: '',
        codeEname: '',
        branchCode: '',
        remark: ''
      },
      addarea: {
        areaCname: '',
        areaEname: '',
        areaCode: '',
        branchCode: ''
      },

      addBtnVisible: false,
      configBtnVisible: false,
      exportBtnVisible: false
    }
  },
  computed: mapState({
    clist: 'riskCodelist',
    blist: 'branchCodelist',
    winHeight: 'winHeight'
  }),
  methods: {
    formatStatus: function (row, column) {
      return row.invoiceStatus == "1" ? "是" : "否";
    },
    formatPolicyStatus: function (row, column) {
      return row.insurancePolicyStatus == "1" ? "是" : "否";
    },
    loadAll() {
      return [
      ];
    },
    querySearchAsync(queryString, cb) {
      var restaurants = this.restaurants;
      var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants;

      clearTimeout(this.timeout);
      this.timeout = setTimeout(() => {
        cb(results);
      }, 1000);
    },
    createStateFilter(queryString) {
      return (state) => {
        return (state.value.indexOf(queryString.toLowerCase()) === 0);
      };
    },
    handleSelect() {
      for (var i in this.restaurants) {
        if (this.restaurants[i].code == this.selectdatas && this.selectdatas != "") {
          this.getAgreementNo.saleName = this.restaurants[i].value.split('-')[0];
          this.getAgreementNo.saleCode = this.restaurants[i].code;
        }
        else {
          this.getAgreementNo.saleName = "";
          this.getAgreementNo.saleCode = "";
        }
      }

    },
    visibleSelect(bool) {
      if (bool) {
        this.selectData();
      }
    },
    blurSelect(event) {
      let _this = this;
      _this.selectdatas = "";
    },
    selectData() {
      let _this = this;
      let para = new FormData();
      _this.restaurants = [];
      para.append('agreementCode', _this.getAgreementNo.agreementNo);
      getSaleName(para).then((res) => {
        let data = res.data.result.sealesPersos;
        if (data.length > 0) {
          for (var i in data) {
            _this.restaurants.push({
              value: data[i].saleName + '-' + data[i].saleVocationCardNo,
              code: data[i].saleVocationCardNo
            });
          }
        }

      }).catch(() => {
        _this.$message({
          message: '查询销售人异常',
          type: 'warning'
        });
      });
    },
    selectVal: function () {
      let para = new FormData();
      para.append("pageSize", 20);
      para.append("pageNumber", this.page);
      para.append("branchCode", this.filters.branchCode);
      this.listLoading = true;
      areaList(para).then((res) => {
        this.total = res.data.result.totalElements;
        this.branchs = res.data.result.content;
        this.listLoading = false;
      });
      if (this.filters.branchCode == 4400 || this.filters.branchCode == 5100) {
        this.sellShow = true;
      }
      else {
        this.sellShow = false;
      }
      for (var i in this.filters.items) {
        if (this.filters.branchCode == this.filters.items[i].code) {
          this.organuzationName = this.filters.items[i].codeCname;
        }
      }
    },
    Addhot: function () {
      this.hotsVisible = true;
      this.getHotsproduct();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getHots(true);
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getHots(true);
    },
    //获取地区列表
    //获取机构地区列表
    getHots(bool) {
      let para = new FormData();
      para.append("pageSize", bool ? this.pageSize : this.exportTotal);
      para.append("pageNumber", bool ? this.page : 1);
      para.append("branchCode", this.filters.branchCode);
      this.listLoading = bool;
      if (!bool) {
        this.loading = this.$loading({
          lock: true,
          text: '正在导出',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
      }
      else {
        this.filters.items = this.blist.result;
      }
      areaList(para).then((res) => {
        this.total = res.data.result.totalElements;
        this.exportTotal = res.data.result.totalElements;
        this.lists = res.data.result.content;
        this.listLoading = false;
        if (!bool) {
          this.loading.close();
          this.export2Excel();
        }
        else {
          this.branchs = res.data.result.content;
        }
      });

    },
    //删除
    handleDel: function (index, row) {
      this.$confirm('确认删除该记录吗?', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        //NProgress.start();
        let para = new FormData();
        para.append("branchCode", row.branchCode);
        para.append("areaCode", row.areaCode);
        removeArea(para).then((res) => {
          this.listLoading = false;
          //NProgress.done();
          this.$message({
            message: '删除成功',
            type: 'success'
          });
          this.selectVal();
        });
      }).catch(() => {

      });
    },

    //table导出excel
    exportExcels: function () {
      this.getHots(false);
    },
    export2Excel: function () {
      require.ensure([], () => {
        const { export_json_to_excel } = require('../../vendor/Export2Excel');
        const tHeader = ['ID', '机构名称', '机构英文名', '机构编码', '地区名称', '地区编码', '业务关系代码', '备注'];
        const filterVal = ['id', 'branchName', 'branchEname', 'branchCode', 'areaName', 'areaCode', 'agreementNo', 'remark'];
        const list = this.lists;
        const data = this.formatJson(filterVal, list);
        export_json_to_excel(tHeader, data, '机构列表excel');
      })
    },
    formatJson: function (filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    },

    //显示修改界面
    handleEdit: function (index, row) {
      this.editFormVisible = true;
      this.editForm = Object.assign({}, row);
    },
    //显示热销界面
    handleHot: function (index, row) {
      if (!this.filters.branchCode) {
        this.$message.error('请选择地区再设置');
      }
      else {
        this.hotForm = {
          productId: row.id,
          branchCode: '',
          remark: '',
          serialNo: '',
          introduceUrl: ''
        }
        this.hotFormVisible = true;
        this.listLoading = true;
        let para = new FormData();
        para.append("productId", row.id);
        para.append("branchCode", this.filters.branchCode);
        getHotProduct(para).then((res) => {
          this.listLoading = false;
          this.hotForm.productId = row.id;
          this.hotForm.branchCode = res.data.result.branchCode;
          this.hotForm.remark = res.data.result.remark;
          this.hotForm.serialNo = res.data.result.serialNo;
          this.hotForm.introduceUrl = res.data.result.introduceUrl;
        });
        this.hotForm.productId = row.id;
      }


    },
    //显示新增界面 StartLeftData:[],
    // StartRightData:[],
    // LeftsData:[],
    // RightsData:[],
    handleAdd: function () {
      $("#input1").css("color", "red");
      if (!this.filters.branchCode) {
        this.$message.error('请选择机构再配置');
      } else {
        var rightData = [];
        this.addData = [];
        this.addNape = [];
        this.addAarry = [];
        this.delAarry = [];
        this.StartLeftData = [];
        this.StartRightData = [];
        this.LeftsData = [];
        this.RightsData = [];
        this.getAgreementNo.agreementNo = '';
        this.getAgreementNo.saleCode = '';
        this.getAgreementNo.saleName = '';
        this.getAgreementNo.contactMobile = '';
        this.getAgreementNo.contactEmail = '';
        this.Forminline = true;
        this.restaurants = [];
        this.state4 = '';
        this.selectdatas = '';
        this.selectValue = '';
        let para = new FormData();
        para.append("pageSize", 100);
        para.append("pageNumber", this.page);
        para.append("branchCode", this.filters.branchCode);
        areaList(para).then((res) => {
          rightData = res.data.result.content;
        });
        this.addFormVisible = true;
        var temp1 = false;
        let list = new FormData();
        let temp = new FormData();
        temp.append("branchCode", this.filters.branchCode);
        list.append("branchCode", this.filters.branchCode);
        list.append("type", "AREACODE");
        getAgreementNo(temp).then((res) => {
          this.getAgreementNo.agreementNo = res.data.result.agreementNo;
          this.getAgreementNo.saleCode = res.data.result.saleCode;
          this.getAgreementNo.saleName = res.data.result.saleName;
          this.getAgreementNo.contactMobile = res.data.result.contactMobile;
          this.getAgreementNo.contactEmail = res.data.result.contactEmail;
          this.getAgreementNo.invoiceStatus = parseInt(res.data.result.invoiceStatus);
          this.getAgreementNo.insurancePolicyStatus = parseInt(res.data.result.insurancePolicyStatus);

          let paras = new FormData();
          paras.append('agreementCode', res.data.result.agreementNo);
          getSaleName(paras).then((res) => {
            let data = res.data.result.sealesPersos;
            var Ishave = false;
            this.restaurants = [];
            for (var i in data) {
              this.restaurants.push({
                value: data[i].saleName + '-' + data[i].saleVocationCardNo,
                code: data[i].saleVocationCardNo
              });
              if (data[i].saleName == this.getAgreementNo.saleName) {
                Ishave = true;
                this.selectValue = data[i].saleVocationCardNo;
                // this.agreementNo.saleName = data[i].saleName;
                // this.agreementNo.saleCode = data[i].saleVocationCardNo;
              }
            }
            if (this.getAgreementNo.saleName == "" || this.getAgreementNo.saleName == null) {
              this.selectValue = "";
            }


            if (!Ishave) {
              this.selectValue = "";
              this.getAgreementNo.saleName = "";
              this.getAgreementNo.saleCode = "";
            }
            this.selectdatas = this.selectValue;
          });
        });
        // codeNodeList(list).then((res) => {
        notConfiguredArea(list).then((res) => {
          var data = res.data.result;
          for (var i = 0; i < data.length; i++) {
            this.addData.push({
              key: i + 1,
              label: data[i].codeCname,
              code: data[i].code
            });
            for (var k in rightData) {
              if (rightData[k].areaCode == data[i].code) {
                this.addNape.push(i + 1);
                this.StartRightData.push(data[i].code);
              }

            }
            this.StartLeftData.push(data[i].code);
          }
          for (var g in this.StartLeftData) {
            for (var q in this.StartRightData) {
              if (this.StartRightData[q] == this.StartLeftData[g]) {
                this.StartLeftData.splice(g, 1);
              }
            }
          }
          this.LeftsData = this.StartLeftData;
          this.RightsData = this.StartRightData;
        });
      }
    },
    //操作addAarry:[],delAarry:[],
    handleChange: function (value, direction, movedKeys) {
      var temp = []; //临时数组1
      var temparray = [];//临时数组2
      if (direction == "right") {
        temparray = this.LeftsData;
        for (var i in movedKeys) {
          for (var k in temparray) {
            if (temparray[k] == this.addData[movedKeys[i] - 1].code) {
              // for(var j in this.LeftsData){
              // if(this.LeftsData[j]==temparray[k]){
              this.LeftsData.splice(k, 1);
              k--;
              // }
              // }
              this.RightsData.push(this.addData[movedKeys[i] - 1].code);
            }
          }
        }
      }
      else {
        temparray = this.RightsData;
        for (var i in movedKeys) {
          for (var k in temparray) {
            if (temparray[k] == this.addData[movedKeys[i] - 1].code) {
              // for(var j in this.LeftsData){
              // if(this.RightsData[j]==temparray[k]){
              this.RightsData.splice(k, 1);
              k--;
              // }
              // }
              this.LeftsData.push(this.addData[movedKeys[i] - 1].code);
            }
          }
        }
      }

    },
    //添加
    addSubmit: function () {

      var Istemp = false;
      this.$refs.getAgreementNo.validate((valid) => {
        if (valid) {
          if (this.RightsData.length > 0) {

            for (var i in this.restaurants) {
              if (this.restaurants[i].code == this.selectdatas && this.selectdatas != "") {
                this.getAgreementNo.saleName = this.restaurants[i].value.split('-')[0];
                this.getAgreementNo.saleCode = this.restaurants[i].code;
              }
              else {
                this.getAgreementNo.saleName = "";
                this.getAgreementNo.saleCode = "";
              }
            }
            let para = new FormData;
            para.append('branchCode', this.filters.branchCode);
            para.append('areaCodes', this.RightsData.join(','));
            para.append('agreementNo', this.getAgreementNo.agreementNo);
            para.append('saleCode', this.getAgreementNo.saleCode);
            para.append('saleName', this.getAgreementNo.saleName);
            para.append('contactMobile', this.getAgreementNo.contactMobile);
            para.append('contactEmail', this.getAgreementNo.contactEmail);
            para.append('invoiceStatus', this.getAgreementNo.invoiceStatus);
            para.append('insurancePolicyStatus', this.getAgreementNo.insurancePolicyStatus);
            // this.$confirm('确认提交吗？', '提示', {}).then(() => {
            addArea(para).then((res) => {
              if (res.data.success) {
                this.$message({
                  message: '操作成功',
                  type: 'success'
                });
                this.addFormVisible = false;
                Istemp = true;
                this.selectVal();
              }
              else {
                this.$message({
                  message: res.data.result,
                  type: 'error'
                });
              }
              this.addLoading = false;
              //NProgress.done();

            });
            let paras = new FormData();
            paras.append("branchCode", this.filters.branchCode);
            paras.append("areaCodes", this.LeftsData.join(','));
            paras.append('agreementNo', this.getAgreementNo.agreementNo);
            paras.append('saleCode', this.getAgreementNo.saleCode);
            paras.append('saleName', this.getAgreementNo.saleName);
            paras.append('contactMobile', this.getAgreementNo.contactMobile);
            paras.append('contactEmail', this.getAgreementNo.contactEmail);
            paras.append('invoiceStatus', this.getAgreementNo.invoiceStatus);
            paras.append('insurancePolicyStatus', this.getAgreementNo.insurancePolicyStatus);
            removeArea(paras).then((res) => {
              if (res.data.success) {
                Istemp = true;
                this.$message({
                  message: '操作成功',
                  type: 'success'
                });
                this.addFormVisible = false;
                this.selectVal();
              }
              else {
                this.$message({
                  message: res.data.result,
                  type: 'error'
                });
              }

              this.listLoading = false;

              //NProgress.done();
            });


            //NProgress.start();
            // this.getHots();
          } else {
            this.$message({
              message: '无有效地区',
              type: 'warning'
            });
          }
        }
      });
    },
    //修改
    editSubmit: function () {
      this.$refs.editForm.validate((valid) => {
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {}).then(() => {
            this.editLoading = true;
            //NProgress.start();
            let para = Object.assign({}, this.editForm);
            para.startDate = (!para.startDate || para.startDate == '') ? '' : util.formatDate.format(new Date(para.startDate), 'yyyy-MM-dd');
            para.endDate = (!para.endDate || para.endDate == '') ? '' : util.formatDate.format(new Date(para.endDate), 'yyyy-MM-dd');
            editProduct(para).then((res) => {
              this.editLoading = false;
              //NProgress.done();
              this.$message({
                message: '提交成功',
                type: 'success'
              });
              this.$refs['editForm'].resetFields();
              this.editFormVisible = false;
              this.getHots(true);
            });
          });
        }
      });
    },
    //热销
    hotSubmit: function () {
      this.$refs.hotForm.validate((valid) => {
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {}).then(() => {
            this.addLoading = true;
            let para = Object.assign({}, this.hotForm);
            editHot(para).then((res) => {
              this.addLoading = false;
              //NProgress.done();
              this.$message({
                message: '提交成功',
                type: 'success'
              });
              this.$refs['hotForm'].resetFields();
              this.hotFormVisible = false;
              this.getHots(true);
            });
          });
        }
      });
    },
    selsChange: function (sels) {
      this.sels = sels;
    },
    hotselsChange: function (hotsels) {
      this.hotsels = hotsels;
    },
    //取消热销
    cancelHot: function (index, row) {
      if (!this.filters.branchCode) {
        this.$message.error('请选择地区再取消');
      } else {
        this.$confirm('确认取消该产品热销吗?', '提示', {
          type: 'warning'
        }).then(() => {
          this.listLoading = true;
          //NProgress.start();
          let para = new FormData();
          para.append("branchCode", this.filters.branchCode);
          para.append("ids", row.id);
          removeHotProduct(para).then((res) => {
            this.listLoading = false;
            //NProgress.done();
            this.$message({
              message: '取消成功',
              type: 'success'
            });
            this.getHots(true);
          });
        }).catch(() => {

        });
      }

    },
    //批量添加热销
    batchAdd: function () {
      var ids = this.hotsels.map(item => item.id).toString();
      this.$confirm('确认添加吗？', '提示', {}).then(() => {
        this.addLoading = true;
        //NProgress.start();
        let para = new FormData();
        para.append("branchCode", this.filters.branchCode);
        para.append("ids", ids);
        addToAreaHot(para).then((res) => {
          this.addLoading = false;
          //NProgress.done();
          this.$message({
            message: '添加成功',
            type: 'success'
          });
          this.hotsVisible = false;
          this.getHots(true);
        });
      });
    },
    //显示新增界面
    Addarea: function () {
      this.addareaVisible = true;
      this.addarea = {
        areaCname: '',
        areaEname: '',
        areaCode: '',
        branchCode: ''
      };
      this.items = this.blist.result;
    },
    //新增提交
    addareaSubmit: function () {
      this.$refs.addarea.validate((valid) => {
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {}).then(() => {
            this.addareaLoading = true;
            //NProgress.start();
            let para = new FormData();
            para.append('areaName', this.addarea.areaCname);
            para.append('areaEname', this.addarea.areaEname);
            para.append('areaCode', this.addarea.areaCode);
            para.append('branchCode', this.addarea.branchCode);
            para.append('branchName', this.addarea.branchCode == "" ? "" : commons.CodeName(this.blist, this.addarea.branchCode, 'BranchCode'));
            addNewArea(para).then((res) => {
              this.addareaLoading = false;
              if (res.data.success) {
                this.$message({
                  message: '提交成功',
                  type: 'success'
                });
                this.$refs['addarea'].resetFields();
                this.addareaVisible = false;
                this.getHots(true);
              }
              else {
                this.$message({
                  message: res.data.result,
                  type: 'error'
                });
              }

            }).catch(() => {
              this.addareaLoading = false;
            });
          });
        }
      });
    },
    //批量取消
    batchRemove: function () {
      var ids = this.sels.map(item => item.id).toString();
      this.$confirm('确认取消选中记录吗？', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        let para = new FormData();
        para.append("branchCode", this.filters.branchCode);
        para.append("ids", ids);
        removeHotProduct(para).then((res) => {
          this.listLoading = false;
          //NProgress.done();
          this.$message({
            message: '取消成功',
            type: 'success'
          });
          this.getHots(true);
        });
      }).catch(() => {

      });
    },

    btnShow: function () {
      let thisData = JSON.parse(sessionStorage.getItem('141'));
      let _this = this;
      $.each(thisData, function (i, j) {
        if (thisData[i] == "organizationAdd") {
          _this.addBtnVisible = true;
        }
        if (thisData[i] == "organizationConfigure") {
          _this.configBtnVisible = true;
        }
        if (thisData[i] == "organizationExport") {
          _this.exportBtnVisible = true;
        }
      });
    }
  },
  mounted() {
    this.restaurants = this.loadAll();
    this.getHots(true);
    this.btnShow();
  }
}

</script>

<style>
.button_style {
  /*background:#08B49E;*/
}
.dialog_title_style {
  width: 100%;
  /*height: 40px;*/
  /*display: inline-block;*/
  line-height: 40px;
  border: 1px solid #e3e3e3;
  line-height: 1;
  font-size: 16px;
  font-weight: 700;
  border-right: 0;
  border-left: 0;
  padding: 10px 0px;
  margin-bottom: 10px;
  background: #fcfcfc;
}
/*#input1{
    display:inline-block !important;
  }
  #input2{
    display:inline-block !important;
  }
  #input2{
    display:inline-block !important;
  }*/
</style>